package bb.lanxing.lib.devices.ble.ble.characteristic.cadence;

import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import bb.lanxing.lib.devices.api.SmartDevice;
import bb.lanxing.lib.devices.base.DeviceContext;
import bb.lanxing.lib.devices.ble.ble.base.BaseBleCharacteristic;
import bb.lanxing.lib.devices.ble.ble.base.BaseBleService;
import java.util.UUID;
import kotlin.Metadata;
import kotlin.jvm.internal.Intrinsics;

public final class CscFeatureCharacteristics extends BaseBleCharacteristic {
    final private static String TAG = "CscFeatureCharacteristics";
    public CscFeatureCharacteristics(BaseBleService bleService) {
        super(bleService);
        Intrinsics.checkNotNullParameter(bleService, "bleService");
    }

    @Override
    public UUID targetUUID() {
        UUID fromString = UUID.fromString("00002A5C-0000-1000-8000-00805f9b34fb");
        Intrinsics.checkNotNullExpressionValue(fromString, "fromString(BLEAttributes.BLE_CADENCE_CSC_FEATURE)");
        return fromString;
    }

    @Override
    public void onValueUpdate(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
//        Intrinsics.checkNotNullParameter(gatt, "gatt");
//        Intrinsics.checkNotNullParameter(characteristic, "characteristic");
        Integer feature = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
        SmartDevice deviceByAddress = DeviceContext.getDeviceByAddress(getBleService().getDevice().getAddress());
//        Intrinsics.checkNotNullExpressionValue(feature, "feature");
        deviceByAddress.setFlags(feature);
        DeviceContext.save(deviceByAddress);
        Context applicationContext = DeviceContext.getApplicationContext();
        Intent intent = new Intent("ACTION_DEVICE_INFORMATION");
        intent.putExtra("EXTRA_DEVICE_TYPE", getBleService().getDevice().getType());
        intent.putExtra("EXTRA_CSC_FUTURE", feature.intValue());
        intent.putExtra("EXTRA_DEVICE_ADDRESS", getBleService().getDevice().getAddress());
        intent.setPackage(DeviceContext.getApplicationContext().getPackageName());
        applicationContext.sendBroadcast(intent);
        Log.d(TAG, "CscFeatureChara" + "CSCFeatures: " + feature);
    }
}
